package com.ruoyi.web.controller.system;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.ViewLog;
import com.ruoyi.system.service.IViewLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * viewLogController
 * 
 * @author ruoyi
 * @date 2025-05-30
 */
@RestController
@RequestMapping("/system/viewLog")
public class SystemViewLogController extends BaseController
{
    @Autowired
    private IViewLogService viewLogService;

    /**s
     * 查询viewLog列
     */
//    @PreAuthorize("@ss.hasPermi('system:viewLog:list')")
    @GetMapping("/list")
    public TableDataInfo list(ViewLog viewLog)
    {
        startPage();
        List<ViewLog> list = viewLogService.selectViewLogList(viewLog);
        return getDataTable(list);
    }

    /**
     * 导出viewLog列表
     */
//    @PreAuthorize("@ss.hasPermi('system:viewLog:export')")
    @Log(title = "viewLog", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ViewLog viewLog)
    {
        List<ViewLog> list = viewLogService.selectViewLogList(viewLog);
        ExcelUtil<ViewLog> util = new ExcelUtil<ViewLog>(ViewLog.class);
        util.exportExcel(response, list, "viewLog数据");
    }

    /**
     * 获取viewLog详细信息
     */
//    @PreAuthorize("@ss.hasPermi('system:viewLog:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(viewLogService.selectViewLogById(id));
    }

    /**
     * 新增viewLog
     */
//    @PreAuthorize("@ss.hasPermi('system:viewLog:add')")
//    @Log(title = "viewLog", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ViewLog viewLog)
    {
        return toAjax(viewLogService.insertViewLog(viewLog));
    }

    /**
     * 修改viewLog
     */
    @PreAuthorize("@ss.hasPermi('system:viewLog:edit')")
    @Log(title = "viewLog", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ViewLog viewLog)
    {
        return toAjax(viewLogService.updateViewLog(viewLog));
    }

    /**
     * 删除viewLog
     */
    @PreAuthorize("@ss.hasPermi('system:viewLog:remove')")
    @Log(title = "viewLog", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(viewLogService.deleteViewLogByIds(ids));
    }
}
